Package-level declarations

Types

Link copied to clipboard
sealed interface Either<L, R>

Represents one of the possible values.

Link copied to clipboard
value class KOptional<T>

Optional implementation that allows holding null values.

Functions

Link copied to clipboard
inline fun invalidArg(message: Any): Nothing
Link copied to clipboard
inline fun invalidIndex(message: Any): Nothing
Link copied to clipboard
inline fun <T : Any> notNullResult(value: T?): Result<T>
inline fun <T : Any> notNullResult(value: T?, message: () -> String): Result<T>

Converts the given value to a Result, that stores a NullPointerException when the value is null.

Link copied to clipboard
inline fun unsupportedOperation(message: Any): Nothing

Inherited functions

Link copied to clipboard
inline fun <L, R, O> Either<L, R>.fold(ifLeft: (L) -> O, ifRight: (R) -> O): O

inline fun <T, R> KOptional<T>.fold(ifPresent: (T) -> R, ifEmpty: () -> R): R

Transforms the value with the ifPresent function if it's present, or the one provided by ifEmpty otherwise.

Link copied to clipboard
inline fun <T> KOptional<T>.getOrDefault(default: T): T

Returns the value if it's present, or default otherwise.

Link copied to clipboard
inline fun <T> KOptional<T>.getOrElse(action: () -> T): T

Returns the value if it's present, or the one provided by the action otherwise.

Link copied to clipboard
inline fun <T> KOptional<T>.ifEmpty(action: () -> Unit): KOptional<T>

Executes the provided action if the value is absent.

Link copied to clipboard
inline fun <L, R> Either<L, R>.ifLeft(action: (L) -> Unit): Either<L, R>
Link copied to clipboard
inline fun <T> KOptional<T>.ifPresent(action: (T) -> Unit): KOptional<T>

Executes the provided action if the value is present.

Link copied to clipboard
inline fun <L, R> Either<L, R>.ifRight(action: (R) -> Unit): Either<L, R>
Link copied to clipboard
fun <T : Throwable> T.inherit(other: Throwable): T
Link copied to clipboard
inline fun <L, R> Either<L, R>.leftOrDefault(default: L): L
Link copied to clipboard
inline fun <L, R> Either<L, R>.leftOrElse(action: (R) -> L): L
Link copied to clipboard
inline fun <L, R> Either<L, R>.leftOrNull(): L?
Link copied to clipboard
inline fun <L, R> Either<L, R>.leftOrThrow(): L
Link copied to clipboard
inline fun <T, R> KOptional<T>.map(action: (T) -> R): KOptional<R>

Transforms the value with the provided action if it's present.

Link copied to clipboard
inline fun <T> Result<T>.mapException(transform: (Throwable) -> Throwable): Result<T>

Transforms the result exception if it's a failure, otherwise returns itself.

Link copied to clipboard
inline fun <L, R, O> Either<L, R>.mapLeft(action: (L) -> O): Either<O, R>
Link copied to clipboard
inline fun <T, R> Result<T>.mapResult(transform: (T) -> Result<R>): Result<R>

If the result is successful, replaces it with the value returned by the transform operation.

Link copied to clipboard
inline fun <L, R, O> Either<L, R>.mapRight(action: (R) -> O): Either<L, O>
Link copied to clipboard
inline fun <L, R> Either<L, R>.rightOrDefault(default: R): R
Link copied to clipboard
inline fun <L, R> Either<L, R>.rightOrElse(action: (L) -> R): R
Link copied to clipboard
inline fun <L, R> Either<L, R>.rightOrNull(): R?
Link copied to clipboard
inline fun <L, R> Either<L, R>.rightOrThrow(): R
Link copied to clipboard
inline fun <L, R> Either<L, R>.swap(): Either<R, L>